﻿using System;
using System.Collections;
using System.Collections.Generic;


using AUV5.Model;
using AUV5.DAL.Interface;

namespace AUV5.BLL
{
    /// <summary>
    /// 功能：     BlackList业务逻辑实现
    /// 作者：     lwl
    /// 日期：     2011/10/14
    /// </summary>
    public class BlackListBLL
    {
        private static BlackListBLL instance = null;
        private static object syncRoot = new object();
        //private IDaoManager daoManager = ServiceConfig.Instance.DaoManager;
        private IBlackListDao dao = null;

        private BlackListBLL()
        {
            dao =DAL.Dao.BlackListSqlMapDao.Instance;
        }

        public static BlackListBLL Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new BlackListBLL();
                        }
                    }
                }
                return instance;
            }
        }

        /// <summary>
        /// 得到最大行数
        /// </summary>
        /// <returns></returns>
        public int GetMaxCounts()
        {
            try
            {
                //daoManager.BeginTransaction();

                int count = dao.GetMaxCounts();

                //daoManager.CommitTransaction();

                return count;
            }
            catch
            {
                //daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<BlackList> GetList()
        {
            try
            {
                //daoManager.BeginTransaction();

                System.Collections.Generic.IList<BlackList> list = dao.GetList();

                //daoManager.CommitTransaction();

                return list;
            }
            catch
            {
                //daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="TopCounts"></param>
        /// <returns></returns>
        private System.Collections.Generic.IList<BlackList> GetListByParameters(object TopCounts, BlackList blacklist)
        {
            try
            {
                //daoManager.BeginTransaction();

                Hashtable ht = new Hashtable();
                ht.Add("TopCounts", TopCounts);
                System.Collections.Generic.IList<BlackList> list = dao.GetListByParameters(ht);

                //daoManager.CommitTransaction();

                return list;
            }
            catch
            {
                //daoManager.RollBackTransaction();
                throw;
            }
        }


        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="ListID"></param>
        /// <returns></returns>
        public BlackList GetDetail(System.String listid)
        {
            try
            {
                ///daoManager.BeginTransaction();
                BlackList bl = new BlackList();
                bl.ListID = listid;
                return dao.GetDetail(bl);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }


        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="blacklist"></param>
        /// <returns></returns>
        public object Add(BlackList blacklist)
        {
            //int id = GetId("SYS_UserInfoTemp");
            //sys_userinfotemp.UserID = id;

            try
            {
                ///daoManager.BeginTransaction();
                blacklist.State = (int)Common.Enum.auvState.Enabled;
                blacklist.IsDel = (int)Common.Enum.auvDel.NotDel;
                blacklist.CreateDate = DateTime.Now;
                blacklist.UpdateDate = DateTime.Now;
                blacklist.BeginDate = DateTime.Now;
                blacklist.EndDate= DateTime.Now;


                return dao.Add(blacklist);
                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="blacklist"></param>
        /// <returns></returns>
        public int Update(BlackList blacklist)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.Update(blacklist);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ListID"></param>
        /// <returns></returns>
        public int Delete(System.String listid)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.Delete(listid);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="blacklist"></param>
        /// <returns></returns>
        public int Delete(BlackList blacklist)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.Delete(blacklist);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 查询一个用户是否在另一个用户的黑名单中
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="blackuserid"></param>
        public BlackList GetDetailByUserID(string userid, string blackuserid)
        {
            BlackList bl=new BlackList();
            bl.UserID=userid;
            bl.BlackUser=blackuserid;
            return dao.GetDetail(bl);
        }
    }
}
